using UnityEngine;
using UnityEditor;
using System.Collections.Generic;


// 确保编辑器脚本放在Editor文件夹中
[CustomEditor(typeof(OCTreeRender))]
public class OCTreeRenderEditor : Editor
{
    public override void OnInspectorGUI()
    {
        OCTreeRender render = (OCTreeRender)target;
        var oldTarget = render.target;
        //EditorGUI.BeginChangeCheck();
        base.OnInspectorGUI();
        if (render.target != oldTarget)
        {
             render.UpdateTarget();
        }
        
        serializedObject.Update();

        if (render.isEditModel == OCEditorType.EDITOR)
        {
            if (GUILayout.Button("转换为数据"))
            {
                render.isEditModel = OCEditorType.DATA_ARRAY;

                render.changeToDataArray();

            }
        }
        else if (render.isEditModel == OCEditorType.DATA_ARRAY)
        {
            if (GUILayout.Button("转换为场景对象"))
            {
                render.isEditModel = OCEditorType.EDITOR;
                render.dataToPerfabs();
            }
        }
         
        // 应用更改
        serializedObject.ApplyModifiedProperties();
    }
}
